package com.tj.jinzao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.tj.jinzao.R;
import com.tj.jinzao.base.BaseListAdapter;
import com.tj.jinzao.model.FamilyMember;

import java.util.concurrent.CopyOnWriteArrayList;


/**
 * 选择用户dialog Adapter
 * Created by wjy on 2019/1/10.
 */
public class ChooseFamilyMemberDialogAdapter extends BaseListAdapter<FamilyMember, ChooseFamilyMemberDialogAdapter.ViewHolder> {

    public ChooseFamilyMemberDialogAdapter(Context context, CopyOnWriteArrayList data) {
        super(context, data);
    }

    private View.OnClickListener mListener;

    public void setListener(View.OnClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_family_member_dialog, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        FamilyMember member = mData.get(position);
        holder.name.setText(member.getName());
        holder.name.setTag(R.id.data,member.getId());
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        Button name;

        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.btn_name);
            name.setOnClickListener(mListener);
        }
    }


}
